home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue32 / forms / NDXDemos / m2main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-02-22  |  2.9 KB  |  131 lines

  1. unit M2Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, TabNotBk, ExtCtrls, ComCtrls, PrevForm;
  8.  
  9. type
  10.   TOffsRec = record
  11.     Offs: LongInt;
  12.     Len: integer;
  13.   end;
  14.  
  15.   TForm1 = class(TForm)
  16.     OpenDialog1: TOpenDialog;
  17.     Panel1: TPanel;
  18.     Label2: TLabel;
  19.     Label3: TLabel;
  20.     Bevel1: TBevel;
  21.     BitBtn2: TBitBtn;
  22.     BitBtn1: TBitBtn;
  23.     BitBtn3: TBitBtn;
  24.     BitBtn4: TBitBtn;
  25.     Label7: TLabel;
  26.     ListBox2: TListBox;
  27.     Memo1: TMemo;
  28.     Label4: TLabel;
  29.     ListBox1: TListBox;
  30.     Label1: TLabel;
  31.     BitBtn5: TBitBtn;
  32.     procedure BitBtn2Click(Sender: TObject);
  33.     procedure BitBtn1Click(Sender: TObject);
  34.     procedure BitBtn3Click(Sender: TObject);
  35.     procedure BitBtn4Click(Sender: TObject);
  36.     procedure BitBtn5Click(Sender: TObject);
  37.   private
  38.     { Private declarations }
  39.   public
  40.     { Public declarations }
  41.   end;
  42.  
  43. var
  44.   Form1: TForm1;
  45.  
  46. implementation
  47.  
  48. {$R *.DFM}
  49.  
  50. procedure TForm1.BitBtn2Click(Sender: TObject);
  51. begin
  52.   if OpenDialog1.Execute then
  53.   begin
  54.     Label3.Caption := OpenDialog1.FileName;
  55.     Memo1.Lines.LoadFromFile(Label3.Caption);
  56.   end;
  57. end;
  58.  
  59. procedure TForm1.BitBtn1Click(Sender: TObject);
  60. var
  61.   Index: file of TOffsRec;
  62.   i: LongInt;
  63.   OffsRec: TOffsRec;
  64. begin
  65.   { assign and create index file }
  66.   AssignFile(Index, ChangeFileExt(Label3.Caption, '.NDX'));
  67.   Rewrite(Index);
  68.   try
  69.     for i := 0 to ListBox1.Items.Count-1 do
  70.     begin
  71.       OffsRec.Offs := StrToInt(ListBox1.Items[i]);
  72.       OffsRec.Len := StrToInt(ListBox2.Items[i]);
  73.       Write(Index, OffsRec); { write offset to index }
  74.     end;
  75.   finally
  76.     { clean up }
  77.     CloseFile(Index)
  78.   end;
  79. end;
  80.  
  81. procedure TForm1.BitBtn3Click(Sender: TObject);
  82. begin
  83.   Listbox1.Items.Clear;
  84.   Listbox2.Items.Clear;
  85. end;
  86.  
  87. procedure TForm1.BitBtn4Click(Sender: TObject);
  88. var
  89.   j: integer;
  90.   F: TFileStream;
  91.   Index: file of TOffsRec;
  92.   S: string;
  93.   OffsRec: TOffsRec;
  94. begin
  95.   { open form file }
  96.   F := TFileStream.Create(Label3.Caption, fmOpenWrite);
  97.   try
  98.     { assign and open index file }
  99.     AssignFile(Index, ChangeFileExt(Label3.Caption, '.NDX'));
  100.     Reset(Index);
  101.     try
  102.       { iterate through index offsets }
  103.       for j := 0 to FileSize(Index)-1 do
  104.       begin
  105.         Read(Index, OffsRec);
  106.         { seek to offset }
  107.         F.Seek(OffsRec.Offs, 0);
  108.         S := Format('%*s', [OffsRec.Len, 'Offset: '+IntToStr(OffsRec.Offs)]);
  109.         { write data to stream }
  110.         F.Write(S[1], Length(S));
  111.       end;
  112.     finally
  113.       CloseFile(Index);
  114.     end;
  115.   finally
  116.     { clean up }
  117.     F.Free;
  118.   end;
  119.   { show file in memo }
  120.   CCForm.FileToShow := Label3.Caption;
  121.   CCForm.Show;
  122. end;
  123.  
  124. procedure TForm1.BitBtn5Click(Sender: TObject);
  125. begin
  126.   ListBox1.Items.Add(IntToStr(Memo1.SelStart));
  127.   ListBox2.Items.Add(IntToStr(Memo1.SelLength));
  128. end;
  129.  
  130. end.
  131.